//
//  VisitorView.swift
//  WBDemo
//
//  Created by Jin on 17/04/2018.
//  Copyright © 2018 com.baidu.123. All rights reserved.
//

import UIKit

class VisitorView: UIView {
    @IBOutlet var registerBtn:UIButton!
    @IBOutlet var loginBtn:UIButton!
    @IBOutlet var rotationView: UIImageView!
    @IBOutlet var iconView: UIImageView!
    @IBOutlet var titleLabel: UILabel!

    // MARK: - 外部控制方法
    func setupVisitorInfo(imageName:String?,title:String) {
        
        //首页
        guard let name = imageName else {
            startAnimation()
            return
        }
        
        //其他页面
        iconView.image = UIImage(named: name)
        titleLabel.text = title
        rotationView.isHidden = true
    }
    
    /// 快速创建方法
    class func visitorView() -> VisitorView{
        return Bundle.main.loadNibNamed("VisitorView", owner: nil, options: nil)?.last! as! VisitorView
    }
    
    // MARK: - 内部控制方法
    private func startAnimation(){
        let animation = CABasicAnimation(keyPath: "transform.rotation")
        animation.toValue = 2 * Double.pi
        animation.duration = 10.0
        animation.repeatCount = MAXFLOAT
        
        animation.isRemovedOnCompletion = false
        rotationView.layer.add(animation, forKey: nil)
    }
    
}
